﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    class DbHelper
    {
        public static readonly string conString = "server = .; uid = sa; pwd = seventeen111; database = CwordDB";

        public static DataTable GetTable(string cmdString)
        {
            SqlConnection connection = new SqlConnection(conString);

            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdString, conString);

            connection.Open();
            
            DataTable table = new DataTable();

            dataAdapter.Fill(table);

            return table;
        }
        /// <summary>
        /// 增加修改删除
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int AddOrEditOrDeleSave(string sql)
        {
            SqlConnection connection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand(sql, connection);

            connection.Open();

            return command.ExecuteNonQuery();
        }


    }
}
